package com.tdengine.controller;

import com.tdengine.mapper.TDDataBaseMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags = {"数据库管理"})
@RequestMapping("database")
public class TDDataBaseController {

    @Autowired
    TDDataBaseMapper dataBaseMapper;

    @ApiOperation("创建数据库")
    @GetMapping("createDB")
    @ApiImplicitParam(name = "dbName",value = "数据库名称")
    public String createDB(@RequestParam String dbName){
        int number = dataBaseMapper.createDB(dbName);
        return "创建成功";
    }

    @ApiOperation("删除数据库")
    @GetMapping("deleteDB")
    @ApiImplicitParam(name = "dbName",value = "数据库名称")
    public String deleteDB(@RequestParam String dbName){
        dataBaseMapper.deleteDB(dbName);
        return "删除成功";
    }

    @ApiOperation("查看数据库配置信息")
    @GetMapping("DBSetting")
    @ApiImplicitParam(name = "dbName",value = "数据库名称")
    public Map<String,Object> DBSetting(@RequestParam String dbName){
        return dataBaseMapper.DBSetting(dbName);
    }

    @ApiOperation("修改数据库")
    @GetMapping("updateDB")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dbName",value = "数据库名称"),
            @ApiImplicitParam(name = "dbName",value = "数据库名称")
    })
    public String updateDB(@RequestParam String dbName,@RequestParam("keep") String keep){
        dataBaseMapper.updateDB(dbName,keep);
        return "修改成功";
    }
}
